<template>
	<view class="p-10">
		<view class="main">
			<my-forms ref="form" :model="formModel" :label-position="'top'" :formItem="formData" :disabled="true" label-width="120px"></my-forms>

			<u-button class="m-t-20" type="primary" shape="circle" text="确定" @click="submit()"></u-button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { postUpdateState } from '@/api/manage.js';

onLoad((e) => {
	formModel.value = JSON.parse(e.data);
	// formModel.value.rejectReason = '';
});

// 校验表单数据
let formData = ref([
	{
		label: '驳回原因',
		prop: 'rejectReason',
		type: 'textarea',
		required: true
	}
]);
const form = ref(null);
const formModel = ref({});

//提交
const submit = () => {
	form.value.$refs.refMyForm
		.validate()
		.then(async (res) => {
			postUpdateState([{ ...formModel.value, approvalStatus: 1, proId: formModel.value.id }]).then((res) => {
				if (res.code == 200) {
					uni.showToast({
						icon: 'success',
						title: `驳回成功`
					});
					uni.navigateBack({
						delta: 2 // 返回的页面数，如果是1则返回上一页
					});
				} else {
					uni.showToast({
						icon: 'fail',
						title: res.msg
					});
				}
			});
		})
		.catch((err) => {
			uni.showToast({
				icon: 'error',
				title: err[0].errorMessage
			});
		});
};
</script>

<style lang="scss" scoped>
.main {
	background-color: white;
	padding: 10px;
	border-radius: 10px;
}
</style>
